
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hotwork/Myapplication.dart';
import 'package:flutter_hotwork/bean/userInfoList.dart';
import 'package:flutter_hotwork/homepage/BaseTitleBar.dart';
import 'package:flutter_hotwork/homepage/BaseViewBar.dart';

import 'ChangeAct.dart';


class ReYongHuXinXiScreen extends StatefulWidget {
  @override
  ReYongHuXinXiState createState() => new ReYongHuXinXiState();

}

int firstrefresh = 0;

class ReYongHuXinXiState extends State<ReYongHuXinXiScreen> {

List<userinfo> searchbean = new List();
  final textEditingController = TextEditingController();


  @override
  Widget build(BuildContext context) {
    ScrollController controller = ScrollController();
    double rpx = MediaQuery.of(context).size.width / 750;
    textEditingController.addListener(() {
      print('input:${textEditingController.text}');

      searchbean.clear();
      for(int i = 0;i< MyApplication.alluserlist.result.length;i++){
        if( MyApplication.alluserlist.result[i].fullName.contains(textEditingController.text)){
          searchbean.add(MyApplication.alluserlist.result[i]);
        }
      }
      setState(() {

      });
    });
    genUserList(context, controller) {

      if(searchbean.length>0&&textEditingController.text.length>0){
        return  genContentList(
            searchbean, context, controller
        );
      }else{
        if(null!=MyApplication.alluserlist&&null!= MyApplication.alluserlist.result){
          return  genContentList(
              MyApplication.alluserlist.result, context, controller
          );
        }else{
          return Container();
        }

      }
    }
    return Scaffold(
      appBar: new BaseViewBar(
          childView: new BaseTitleBar(
            "热用户信息",
            leftIcon: 'images/fanhui.png',
            rightIcon:  '',
            rightClick: () {
              print("点击了右边干嘛啊。。。哦");

            },
            leftClick: () {
              print("点击了左边干嘛啊。。。哦");
              Navigator.of(context).pop();
            },
          ),
          preferredSize: Size.fromHeight(50.0)),


      body:
      Container(
        child:
        Column(
          children: [
            Container(
              height: 30,
              margin: EdgeInsets.only(left: 0, top: 10, right: 10, bottom: 10),
              width: rpx * 600,
              padding: EdgeInsets.only(left: 10, top: 0, right: 10, bottom: 0),
              decoration: BoxDecoration(
                border: new Border.all(color: Color(0xFF9E9E9E), width: 0.5),
                // 边色与边宽度
                color: Colors.white,
                // 底色
                //        borderRadius: new BorderRadius.circular((20.0)), // 圆角度
                borderRadius: BorderRadius.all(Radius.circular(15)),
              ),
              child:
              Center(child: TextField(
                controller: textEditingController,
                style: TextStyle(color: Colors.grey),
//                            controller: phoneController,
                decoration: InputDecoration(
                  icon: Icon(Icons.search),
                  contentPadding: EdgeInsets.all(8.0),
                  hintText: '搜索用户名',
                  hintStyle: TextStyle(color: Colors.grey),
//                            helperText: '请输入注册的手机号',
                  border: InputBorder.none,
                ),
                autofocus: false,
              ),),
            ),
            Expanded(
              child:
              genUserList(
                 context, controller
              ),
            ),
          ],
        ),
      ),
    );
  }
}

String getDDFStatus(int value){
  if(value==0){
    return "手动";
  }else if(value == 1){
    return "自动";
  }else{
    return "半自动";
  }

}
genContentList(List<userinfo> data, BuildContext context, controller) {
  double rpx = MediaQuery
      .of(context)
      .size
      .width / 750;

  return ListView.builder(
    shrinkWrap: true,
    controller: controller,
    itemCount: data.length,
    itemBuilder: (BuildContext context, int index) {
      return
        Container(
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(Radius.circular(5)),
            boxShadow: <BoxShadow>[ //设置阴影
              new BoxShadow(
                color: Colors.grey, //阴影颜色
                blurRadius: 5.0, //阴影大小
              ),
            ],
          ),

          margin: EdgeInsets.only(left: 10, top: 10, right: 10, bottom: 10),
          height: 430 * rpx,
          child: Column(
            children: <Widget>[
              Container(
                height: 10,
              ),
              Container(
                padding: EdgeInsets.only(
                    left: 10, top: 0, right: 10, bottom: 0),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Container(
                      width: 2,
                      height: 15,
                      color: Colors.blue,
                    ),
                    Container(
                      width: 10,
                    ),
                    Container(
                      width: 200,
                      child: Text(data[index].fullName,
                      style: new TextStyle(color: Color(0xFF333333),
                        fontSize: 12.0,
                      ),),),

                    Flexible(fit: FlexFit.tight, child: SizedBox()),


                    InkWell(
                      onTap: (){
                        if( MyApplication.loginuserinfo.userInfo.amHotuser==0){
                          MyApplication.changedidongfabean = data[index];
                          Navigator.push(context, MaterialPageRoute(builder: (context) {
                            return new changeactivity();
                          }));
                        }

                      } ,
                      child:
                      Container(
                        margin: EdgeInsets.only(top: 5,bottom: 5),
                        padding: EdgeInsets.only(top: 3),
                        decoration: BoxDecoration(
                          // border: new Border.all(color: Color(0xFF9E9E9E), width: 0.5), // 边色与边宽度
                          color: MyApplication.loginuserinfo.userInfo.amHotuser==0?Colors.blue:Colors.grey, // 底色
                          borderRadius: BorderRadius.all(Radius.circular(5)),
                        ),
                        width: 80,
                        height: 20,
                        child:
                        Text("电动阀控制",style: TextStyle(color: Colors.white,fontSize: 10),                textAlign: TextAlign.center,),

                      ),
                    ),
                  ],
                ),
              ),
              Container(
                height: 1,
                margin: EdgeInsets.only(
                    left: 10, top: 5, right: 10, bottom: 0),
                color: Colors.grey[300],
              ),

              Container(
                padding: EdgeInsets.only(left: 10,top: 0,right: 10,bottom:0),
                margin: EdgeInsets.only(left: 0,top: 5,right: 0,bottom: 0),
                child: Row(
                  children: [
                    // Image(height:20,width: 20,image: AssetImage('images/mingcheng.png')),
                    Container(
                      width: 10,
                    ),
                    Container(
                      width: 150,
                      child:
                      Text("余额（元）:"+data[index].balance.toString(),style: new TextStyle(color: Color(0xFF333333),
                        fontSize: 12.0,
                      ),),
                    ),
                    // Image(height:20,width: 20,image: AssetImage('images/weizhi.png')),
                    Container(
                      width: 10,
                    ),
                    Text("余汽（吨）:"+data[index].steam.toString(),style: new TextStyle(color: Color(0xFF333333),
                      fontSize: 12.0,
                    ),),
                  ],
                ),
              ),
              Container(
                padding: EdgeInsets.only(left: 10,top: 0,right: 10,bottom:0),
                margin: EdgeInsets.only(left: 0,top: 5,right: 0,bottom: 0),
                child: Row(
                  children: [
                    // Image(height:20,width: 20,image: AssetImage('images/mingcheng.png')),
                    Container(
                      width: 10,
                    ),
                    Container(
                      width: 150,
                      child:
                      Text("联系人:"+data[index].departContacter.toString(),style: new TextStyle(color: Color(0xFF333333),
                        fontSize: 12.0,
                      ),),
                    ),
                    // Image(height:20,width: 20,image: AssetImage('images/weizhi.png')),
                    Container(
                      width: 10,
                    ),
                    Text("手机:"+data[index].contacterTel.toString(),style: new TextStyle(color: Color(0xFF333333),
                      fontSize: 12.0,
                    ),),
                  ],
                ),
              ),
              Container(
                padding: EdgeInsets.only(left: 10,top: 0,right: 10,bottom:0),
                margin: EdgeInsets.only(left: 0,top: 5,right: 0,bottom: 0),
                child: Row(
                  children: [
                    // Image(height:20,width: 20,image: AssetImage('images/mingcheng.png')),
                    Container(
                      width: 10,
                    ),
                    Container(
                      width: 150,
                      child:
                      Text("用热状态:"+(data[index].state==0?"停用":"在用"),style: new TextStyle(color: Color(0xFF333333),
                        fontSize: 12.0,
                      ),),
                    ),
                    // Image(height:20,width: 20,image: AssetImage('images/weizhi.png')),
                    Container(
                      width: 10,
                    ),
                    Text("结算方案:"+data[index].tbsSchemesName.toString(),style: new TextStyle(color: Color(0xFF333333),
                      fontSize: 12.0,
                    ),),
                  ],
                ),
              ),
              Container(
                padding: EdgeInsets.only(left: 10,top: 0,right: 10,bottom:0),
                margin: EdgeInsets.only(left: 0,top: 5,right: 0,bottom: 0),
                child: Row(
                  children: [
                    // Image(height:20,width: 20,image: AssetImage('images/mingcheng.png')),
                    Container(
                      width: 10,
                    ),
                    Container(
                      width: 150,
                      child:
                      Text("报警方案:"+data[index].schemeName,style: new TextStyle(color: Color(0xFF333333),
                        fontSize: 12.0,
                      ),),
                    ),
                    // Image(height:20,width: 20,image: AssetImage('images/weizhi.png')),
                    Container(
                      width: 10,
                    ),
                    Text("结算价格:"+data[index].price.toString(),style: new TextStyle(color: Color(0xFF333333),
                      fontSize: 12.0,
                    ),),
                  ],
                ),
              ),
              Container(
                padding: EdgeInsets.only(left: 10,top: 0,right: 10,bottom:0),
                margin: EdgeInsets.only(left: 0,top: 5,right: 0,bottom: 0),
                child: Row(
                  children: [
                    // Image(height:20,width: 20,image: AssetImage('images/mingcheng.png')),
                    Container(
                      width: 10,
                    ),
                    Container(
                      width: 150,
                      child:
                      Text("付费类型:"+(data[index].payType==0?"预付费":"后付费"),style: new TextStyle(color: Color(0xFF333333),
                        fontSize: 12.0,
                      ),),
                    ),
                    // Image(height:20,width: 20,image: AssetImage('images/weizhi.png')),
                    Container(
                      width: 10,
                    ),
                    Container(
                      width: 150,
                      child:
                      Text("阀门控制:"+(getDDFStatus(data[index].valveControl)),style: new TextStyle(color: Color(0xFF333333),
                        fontSize: 12.0,
                      ),),
                    ),
                  ],
                ),
              ),
              Container(height: 10,),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(
                    width: 80,
                    child:
                    Column(
                      mainAxisAlignment: MainAxisAlignment.center,
//                      textDirection: TextDirection.,
                      children: [
                        data[index].valveState!=3?
                        Image(
                          height: 15,
                          width: 15,
                          image:AssetImage(data[index].valveState==0?"images/lvse.png":"images/hongse.png"),)
                            :Container(  height: 15,
                          width: 15,),
                        Text("电动阀",style: TextStyle(color: const Color(0xFF333333),fontSize: 12),),
                      ],
                    ),
                  ),
                  Container(
                    width: 0.5,
                    height: 30,
                    margin: EdgeInsets.only(left: 0, right: 0, top:0, bottom: 0),
                    decoration: BoxDecoration(
//                  border: new Border.all(color: Color(0xFF9E9E9E), width: 0.5), // 边色与边宽度
                      color: Colors.grey, // 底色
                      //        borderRadius: new BorderRadius.circular((20.0)), // 圆角度
                      borderRadius: BorderRadius.all(Radius.circular(5)),
                    ),

                  ),
                  Container(
                    width: 80,
                    child:
                    Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Image(
                          height: 15,
                          width: 15,
                          image:AssetImage(data[index].dataState==1?"images/lvse.png":"images/hongse.png"),),
                        Text("数据",style: TextStyle(color: const Color(0xFF333333),fontSize: 12),),
                      ],
                    ),
                  ),
                  Container(
                    width: 0.5,
                    height: 30,
                    margin: EdgeInsets.only(left: 0, right: 0, top:0, bottom: 0),
                    decoration: BoxDecoration(
//                  border: new Border.all(color: Color(0xFF9E9E9E), width: 0.5), // 边色与边宽度
                      color: Colors.grey, // 底色
                      //        borderRadius: new BorderRadius.circular((20.0)), // 圆角度
                      borderRadius: BorderRadius.all(Radius.circular(5)),
                    ),

                  ),
                  Container(
                    width: 80,
                    child:
                    Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Image(
                          height: 15,
                          width: 15,
                          image:AssetImage(data[index].commState==1?"images/lvse.png":"images/hongse.png"),),
                        Text("通讯",style: TextStyle(color: const Color(0xFF333333),fontSize: 12),),
                      ],
                    ),
                  ),
                  Container(
                    width: 0.5,
                    height: 30,
                    margin: EdgeInsets.only(left: 0, right: 0, top:0, bottom: 0),
                    decoration: BoxDecoration(
//                  border: new Border.all(color: Color(0xFF9E9E9E), width: 0.5), // 边色与边宽度
                      color: Colors.grey, // 底色
                      //        borderRadius: new BorderRadius.circular((20.0)), // 圆角度
                      borderRadius: BorderRadius.all(Radius.circular(5)),
                    ),

                  ),
                  Container(
                    width: 80,
                    child:
                    Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Image(
                          height: 15,
                          width: 15,
                          image:AssetImage(data[index].alertState==1?"images/lvse.png":"images/hongse.png"),),
                        Text("报警",style: TextStyle(color: const Color(0xFF333333),fontSize: 12),),

                      ],
                    ),
                  ),
                ],
              ),



            ],
          ),
        );
      // Expanded(
      //   child:
      // Flexible(
      //   child:
      // getItemContentList(data[index].focusHotUserVos,context,controller),
      // )
      // )

    },
  );
}
















void _login() {

}